<template>
  <div class="activity-container">
    <div class="news-box">
      <div class="title">
        <h1 class="text-3xl">新闻中心</h1>
      </div>
      <div class="detai-box" v-show="isNull">
        <el-empty description="暂无数据"></el-empty>
      </div>
      <div class="detai-box" v-show="!isNull">
        <div class="content-box">
          <div
            class="content"
            v-for="(item, index) in fliterNews"
            :key="index"
            @click="toinfo(item.newsId)"
          >
            <div class="imgbox">
              <el-image :src="item.newsUrl" :fit="'fill'"></el-image>
            </div>
            <div class="textbox">
              <div class="content-text mb-2">
                {{ item.newsTitle.trim() }}
              </div>
              <!-- <div class="content-introdece text-left text-sm text-gray-500 px-1">
                              {{ item.newsIntroduce }}
                          </div> -->
              <div class="viewBox">
                <div class="time">发布时间：{{ item.newsTime }}</div>
                <div
                  class="view-button rounded-lg flex justify-center align-center"
                >
                  <p>查看详情</p>
                  <i class="el-icon-arrow-right"></i>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="find-button rounded-lg" @click="toMode()">
          <p>查看更多&nbsp;></p>
        </div>
      </div>
    </div>
  </div>
</template>
  
  <script>
export default {
  name: "",
  data() {
    return {
      isNull: true,
      navIndex: 0,
      listNews: [],
      detail: false,
      fliterNews: [],
      newsNum: 0,
    };
  },
  methods: {
    navClick(index) {
      this.navIndex = index;
    },
    // 获取news
    getNews() {
      this.$axios
        .postInfo("findAllNews")
        .then((res) => {
          // console.log(res)
          this.listNews = res.listNews.slice(this.newsNum, this.newsNum + 2);
          this.fliterNews = this.fliterNews.concat(this.listNews);
          if (this.fliterNews.length > 0) {
            this.isNull = false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    toinfo(value) {
      let query = value;
      this.$router.replace({ path: "/news/detail", query: { newsId: value } });
    },
    toMode() {
      this.newsNum += 2;
      this.getNews();
    },
  },
  computed: {
    navFilterList() {
      if (this.navIndex == 0) {
        return this.navList;
      } else {
        return this.navList.filter((item) => {
          return item == this.navList[this.navIndex];
        });
        // console.log(arr)
      }
    },
  },
  created() {
    this.getNews();
  },
};
</script>
  <style  lang="less" scoped>
.activity-container {
  .news-box {
    width: 100%;
    padding-top: 150px;
    padding-bottom: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;

    .title {
      max-width: 1200px;
    }
    .title {
      width: 90%;
      box-shadow: 4px 4px 6px rgb(143, 140, 140);
      @apply rounded-lg;
      background: #2468e57d;
      color: #fff;
      padding: 1rem;
    }
    .detai-box {
      position: relative;
      width: 90%;
      max-width: 1200px;
      margin-top: 50px;
      padding: 1rem;
      background: #fbfbfb;
      @apply rounded-md;

      .content-box {
        position: relative;
        width: 100%;
        margin-top: 30px;

        .content {
          position: relative;
          width: 100%;
          // left: 5%;
          display: flex;
          box-sizing: border-box;
          justify-content: flex-start;
          cursor: pointer;
          padding: 2rem 0rem;
          box-sizing: border-box;

          .imgbox {
            flex-shrink: 0;
            width: 300px;

            .el-image {
              height: 150px;
              width: 250px;
              @apply rounded-lg;

              img {
                @apply rounded-md;
              }
            }
          }

          .textbox {
            height: 180px;
            flex: 1;
            padding-left: 20px;
            box-sizing: border-box;

            .content-text {
              position: relative;
              width: 100%;
              text-align: left;
              font-size: 18px;
              font-weight: 600;
              display: -webkit-box;
              -webkit-line-clamp: 4;
              -webkit-box-orient: vertical;
              overflow: hidden;
              white-space: normal;
              word-break: break-all;
              overflow: hidden;
            }

            .content-introdece {
              -webkit-line-clamp: 3;
              line-clamp: 3;
              -webkit-box-orient: vertical;
              overflow: hidden;
            }

            .viewBox {
              position: relative;
              height: 50%;
              width: 100%;

              .time {
                height: 50%;
                text-align: left;
                font-size: 14px;
                color: rgba(128, 128, 128, 0.649);
              }

              .view-button {
                position: absolute;
                right: 4%;
                width: 120px;
                height: 40px;
                line-height: 40px;
                color: #2469e5;
                border: #2469e5 solid 1px;

                i {
                  line-height: inherit;
                }
              }
            }
          }
        }

        .content::after {
          content: "";
          width: 100%;
          height: 1px;
          background: rgba(128, 128, 128, 0.44);
          position: absolute;
          bottom: 0%;
          left: 0%;
        }

        .content:hover {
          background: #2468e520;

          .viewBox {
            .view-button {
              color: #fff;
              background: #2469e5 !important;
            }
          }
        }
      }

      .find-button {
        position: relative;
        // top: 50%;
        left: 50%;
        transform: translate(-50%);
        margin-top: 50px;
        width: 200px;
        height: 3rem;
        color: #2469e5;
        // border-radius: 24px;
        border: 1px solid #2469e5;
        line-height: 3rem;
        cursor: pointer;
      }

      .find-button.active {
        background: #2469e5;
        color: #fff;
      }
    }
  }
}
</style>